<?php

declare(strict_types=1);

namespace App\Request\Admin;

use App\Constants\ErrorCode;
use App\Exception\BusinessException;
use App\Utils\Wechat\OpenPlatform\OpenPlatform;
use Hyperf\Validation\Request\FormRequest;
use Hyperf\Validation\Rule;

class CooperativeSubmitAuditRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        $templateList = di(\App\Utils\Wechat\OpenPlatform\OpenPlatform::class)->templateList();
        if (!$templateList) {
            throw new BusinessException(ErrorCode::TEMPLATE_LIST_FAIL);
        }
        $templateList = array_column($templateList, 'template_id');
        return [
            'template_id' => ['required', Rule::in($templateList)],
        ];
    }
}
